<?php
namespace app\admin\controller;
use think\Controller;
use think\Session;
use think\Db;
class Login extends Controller
{
    public function index()
    {
        if(request()->isPost()){
            $username = request()->post('username');
            $password = md5(request()->post('password'));
            $result = Db::table('admin')->where(['username'=>$username,'password'=>$password])->find();
            if(count($result) == 0){
                return view('',['type'=>'error']);
            }else{
                Session::set('uid',strval($result['id']));
                Session::set('auth',strval($result['auth']));
                Session::set('this_aid',strval($result['aid']));
                Session::set('aid',strval($result['all_aid']));
                Session::set('type',strval($result['type']));
                $this->redirect('./main');
            }
        }else{
            return view('',['type'=>'']);
        }
    }

    public function quit()
    {
        Session::clear();
        $this->redirect('./index');
    }
}